<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cap.bean.Admin" %>
<%@ page import="cap.bean.Article" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
    Admin admin = (Admin)request.getSession().getAttribute("admin");//管理员信息
    List<Article> artList = (List<Article>)request.getAttribute("artList");//文章列表
    String deleSuccMsg = (String)request.getSession().getAttribute("deleSuccMsg");	//删除文章消息
    String deleErrorMsg = (String)request.getSession().getAttribute("deleErrorMsg");
    int curPage = (Integer)request.getAttribute("curPage");
    int totalPages = (Integer)request.getAttribute("totalPages");
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>博客</title>
    <link href="<%=basePath%>bootstrap/css/blog-home.css"/>
    <link href="<%=basePath%>bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script src="<%=basePath%>bootstrap/js/jquery-2.1.1.js"></script>
</head>
<c:if test="${null!=admin}">
<div class="container">
    <!-- Sidebar -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="<%=basePath %>admin?method=index">博客管理系统</a>
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse navbar-ex1-collapse">
            <ul class="nav navbar-nav side-nav">
                <li><a href="<%=basePath %>admin?method=index"><i class="glyphicon glyphicon-dashboard"></i> 控制面板</a></li>
                <li><a href="<%=basePath%>admin?method=useradmin"><i class="glyphicon glyphicon-cog"></i> 用户管理</a></li>
                <li  class="active"><a href="<%=basePath%>admin?method=SysArticalAdmin"><i class="glyphicon glyphicon-cog"></i> 文章管理</a></li>
                <li><a href="<%=basePath%>admin?method=SysCategoryAdmin"><i class="glyphicon glyphicon-edit"></i> 分类管理</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right navbar-user">
                <li><a href="#"><i class="glyphicon glyphicon-user"></i>${admin.userName}</a></li>
                <li><a href="<%=basePath%>admin?method=logout"><i class="glyphicon glyphicon-off"></i> 登出</a></li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </nav>
    <div  style="position:absolute;top: 2px">
        <div class="row">
            <div class="col-md-12">
                <br>
                <ol class="breadcrumb">
                    <li><a href="<%=basePath%>admin?method=index"><i class="glyphicon glyphicon-dashboard"></i> 控制面板</a></li>
                    <li class="active"><i class="glyphicon glyphicon-edit"></i> 文章管理</li>
                </ol>
            </div>
        </div>
        <c:if test="${null != deleSuccMsg}">
        <div class="row">
            <div class="col-md-12">
                <div class="alert alert-success">${deleSuccMsg}</div>
            </div>
        </div>
        <%
                request.getSession().removeAttribute("deleSuccMsg");
        %>
        </c:if>
        <c:if test="${null != deleErrorMsg}">
        <div class="row">
            <div class="col-md-12">
                <div class="alert alert-error">${deleErrorMsg}</div>
            </div>
        </div>
        <%
                request.getSession().removeAttribute("deleErrorMsg");
        %>
        </c:if>
        <div class="row" style="width: 900px">
            <div class="col-md-12">
                <div class="table-responsive">
                    <table class="table table-hover tablesorter">
                        <thead>
                        <tr>
                            <th>文章标题 </th>
                            <th>作者</th>
                            <th>发布时间</th>
                            <th style="width: 50px;">操作 </th>
                        </tr>
                        </thead>

                        <tbody>
                        <%
                            if ((artList != null) && (artList.size() > 0)) {
                                for (Article art : artList) {
                                    if (0 == art.getIsDelete()) {
                                        String deleUrl = basePath+"admin?method=DeleteSysArtical&artId="+art.getId();

                        %>
                        <tr>
                            <td>
                                <a href="<%=basePath%>comment?method=post&artId=<%=art.getId() %>&userId=<%=art.getUserId() %>" target="_blank">
                                    <%=art.getTitle() %></a></td>
                            <td><%=art.getUsername() %></td>
                            <td><%=art.getPublishTime() %></td>
                            <td>
                                <a onClick="dele('<%=deleUrl %>')"><i class="glyphicon glyphicon-floppy-remove"></i></a>
                            </td>
                        </tr>

                        <%          }
                        }
                        } else { %>
                        <%="获取系统分类失败！" %>
                        <% } %>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <!-- pager -->
        <ul class="pager">
            <c:if test="${curPage>1}">
            <li class="previous"><a href="<%=basePath%>admin.html?action=SysArticalAdmin&curPage=${curPage-1}">&larr; 上一页</a></li>
            </c:if>
            <c:if test="${curPage < totalPages}">
            <li class="next"><a href="<%=basePath%>admin?method=SysArticalAdmin&curPage=${curPage+1}">下一页  &rarr;</a></li>
            </c:if>
        </ul>

    </div>
</div>
</c:if>
<c:if test="${null==admin}">
<%-- 404 page --%>
<jsp:include page="404.jsp"></jsp:include>
</c:if>
<script type="text/javascript">
    function dele(deleUrl) {
        if (confirm("你确定要删除该分类吗？")) {
            location.href = deleUrl;
        }
    }
</script>
<div><audio autoplay="autoplay" loop="true"><source src="music/1.mp3"></audio></div>
</body>
</html>